from PyQt4 import QtGui, QtCore
from os import path as File

class ProjectManager( QtGui.QTabWidget ):

	menuNew 	= None
	menuOpen	= None
	menuSave	= None
	menuClose	= None

	projOpened 	= None


	def __checkMenu( self ):
		enabled = self.projOpened != None
		self.menuSave.setEnabled( enabled )
		self.menuClose.setEnabled( enabled )
		
	def newProject( self ):
		ok = ProjectNew(self)
		
	def openProject( self ):
		self.projOpened = 'teste'

		self.__checkMenu()
		return 

	def saveProject( self ):
		return 

	def closeProject( self ):
		self.projOpened = None

		self.__checkMenu()
		return

	def setupMenu( self, projMenu ):
		"""
		Set the actions for the Projects menu
		"""
		self.menuNew = QtGui.QAction(self.tr("&New"), projMenu)
		self.menuNew.setStatusTip(self.tr("Creates a new project."))
		self.connect(
			self.menuNew,
			QtCore.SIGNAL("triggered()"), 
			self.newProject
		)
		projMenu.addAction( self.menuNew )
		
		self.menuOpen = QtGui.QAction(self.tr("&Open"), projMenu)
		self.menuOpen.setStatusTip(self.tr("Open an existent project."))
		self.connect(
			self.menuOpen, 
			QtCore.SIGNAL("triggered()"), 
			self.openProject
		)
		projMenu.addAction( self.menuOpen )
		
		self.menuSave = QtGui.QAction(self.tr("&Save"), projMenu)
		self.menuSave.setStatusTip(self.tr("Save current project."))
		self.connect(
			self.menuSave, 
			QtCore.SIGNAL("triggered()"), 
			self.saveProject
		)
		projMenu.addAction( self.menuSave )
		self.menuSave.setEnabled( False );
		
		#closeProjAct = QtGui.QAction(self.tr("&Close"),projMenu)
		#closeProjAct.setShortcut(QtGui.QKeySequence( "Ctrl+W" ))
		#self.connect(
			#closeProjAct,
			#QtCore.SIGNAL("triggered()"),
			#self.closeFile
		#)
		#projMenu.addAction( closeProjAct )
		
		projMenu.addSeparator()
	
		self.menuClose = QtGui.QAction(self.tr("&Close"), projMenu)
		self.menuClose.setStatusTip(self.tr("Close current project."))
		self.connect(
			self.menuClose, 
			QtCore.SIGNAL("triggered()"), 
			self.closeProject
		)
		projMenu.addAction( self.menuClose )
		self.menuClose.setEnabled( False );

class ProjectNew( QtGui.QDialog ):
	def __init__( self , parent=None ):
		from Interfaces.ProjectNew import Ui_Form
	
		QtGui.QDialog.__init__( self, parent )
		self.setModal( True )

		self.Form = Ui_Form()
		self.Form.setupUi( self )

		self.connect(self.Form.btn_ok, QtCore.SIGNAL('clicked()'), self.btn_ok_act)
		self.connect(self.Form.btn_cancel, QtCore.SIGNAL('clicked()'), self.btn_cancel_act)

		self.show()

	def btn_ok_act( self ):
		if not str(self.Form.txt_projname.text()):
			QtGui.QMessageBox.critical(self,
				'Error', 'You must fill all fields.',
				QtGui.QMessageBox.Ok, False)
			self.Form.txt_projname.setFocus()
		else:
			QtGui.QMessageBox.information(self,
				'Success', 'Project created successfully.',
				QtGui.QMessageBox.Ok)
			self.close()

		return

	def btn_cancel_act( self ):
		self.close()
		return
